﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TA.Win.Utils.Design;

namespace TA.Turbo.Design
{
	/// <summary>
	/// Provides list of control IDs to a <see cref="TA.Win.Utils.Design.StringCollectionEditor{T}"/>.
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class ControlIdOptionsProvider<T> : IStringOptionsProvider
		where T : BaseControlIdLister, new()
	{
		#region IStringOptionsProvider Members
		/// <summary>
		/// Gets a <see cref="StringOptions"/> object using the specified designer context and provider.
		/// </summary>
		/// <param name="context"></param>
		/// <param name="provider"></param>
		/// <returns></returns>
		public StringOptions GetOptions(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider)
		{
			StringOptions res = new StringOptions();
			res.DuplicatesAllowed = false;

			System.Web.UI.Control startingPoint = context.Instance as System.Web.UI.Control;
			if (startingPoint != null)
			{
				T t = new T();
				string[] controlIds = t.GetControlIdList(startingPoint);

				res.Options = controlIds;
			}
			return res;
		}

		#endregion
	}
}
